package com.zhongkun.datahome.service.constant;

import org.apache.commons.lang3.StringUtils;

/**
 * @Author: lifengsheng
 * @Date: 2025/4/15 14:31
 * @Desc
 */
public enum FileTypeEnum {

    COMMON_PIC("common_pic", "普通图片"),

    PANORAMA_PIC("panorama_pic", "全景图"),

    COMMON_VIDEO("common_video", "普通视频"),

    EXCEL("excel", "表格"),

    PPT("ppt", "幻灯片"),

    DWG("dwg", "DWG文件"),

    WORD("word", "文档"),

    PDF("pdf", "PDF"),

    ATTACHMENT("attachment", "附件");

    private String type;
    private String desc;

    FileTypeEnum(String type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public String getType() {
        return type;
    }

    public String getDesc() {
        return desc;
    }

    public static String getFileType(String fileUrl) {
        if (StringUtils.isBlank(fileUrl)) {
            return StringUtils.EMPTY;
        }

        if (fileUrl.endsWith(".png") || fileUrl.endsWith(".jpg") || fileUrl.endsWith(".jpeg")) {
            return FileTypeEnum.COMMON_PIC.getType();
        }
        if (fileUrl.endsWith(".mp4")) {
            return FileTypeEnum.COMMON_VIDEO.getType();
        }
        if (fileUrl.endsWith(".pdf")) {
            return FileTypeEnum.PDF.getType();
        }
        if (fileUrl.endsWith(".xlsx") || fileUrl.endsWith(".xls")) {
            return FileTypeEnum.EXCEL.getType();
        }
        if (fileUrl.endsWith(".ppt") || fileUrl.endsWith(".pptx")) {
            return FileTypeEnum.PPT.getType();
        }
        if (fileUrl.endsWith(".dwg")) {
            return FileTypeEnum.DWG.getType();
        }
        if (fileUrl.endsWith(".doc") || fileUrl.endsWith(".docx")) {
            return FileTypeEnum.WORD.getType();
        }

        return FileTypeEnum.ATTACHMENT.getType();
    }
}
